#include <iostream>
#include <string>
#include <vector>

void gcj_2011_r0_a()
{
	int location[2] = {1,1};

	// Read and execute sequence.
	int buttons = 0;
	std::cin >> buttons;

	int last_robot = 0;
	int idle = 0;
	int total = 0;
	for (int i = 0; i < buttons; i++)
	{
		std::string who;
		std::cin >> who;
		int next_robot = (who[0] == 'O')? 0 : 1;
		int next_button = 0;
		std::cin >> next_button;

		if (next_robot == last_robot)
		{
			int t = abs(location[next_robot] - next_button) + 1;
			total += t;
			idle += t;
			location[next_robot] = next_button;
		}
		else
		{
			int t = abs(location[next_robot] - next_button);
			t = std::max(t - idle, 0);
			t += 1;
			total += t;
			idle = t;
			location[next_robot] = next_button;
			last_robot = next_robot;
		}
	}
	std::cout << total << std::endl;
}
